﻿
using GameConfig;
using NetCommon;
using RPGGameServer.Dao;
using ServerFrame;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RPGGameServer
{
    class Program
    {
        static void Main(string[] args)
        {
            InitConfig();

            //测试配置表读取
            //Console.WriteLine(ChargeProvider.GetNameById("1"));
            ServerSetting setting = new ServerSetting();
            //给消息编码器与消息解码器赋值
            setting.messageDecode = MessageEncoding.Decode;
            setting.messageEncode = MessageEncoding.Encoding;

            //给消息长度编码器和解码器赋值
            setting.lengthDecode = LengthEncoding.Decode;
            setting.lengthEncode = LengthEncoding.Encode;

            
            //给消息加密解密器赋值
            setting.messageDecrypt = DEncrypt.Decrypt;
            setting.messageEncrypt = DEncrypt.Encrypt;

            //给消息压缩解压器赋值
            setting.compressDecode = CompressEncoding.Decode;
            setting.compressEncode = CompressEncoding.Encode;

            setting.center = new HandlerCenter();

            UserToken.setting = setting;

            Console.WriteLine("服务器开始启动");
            TestMySqlAdd();

            //启动服务器
            ServerAgent server = new ServerAgent();//实例化服务器代理\
            server.cache = new UserTokenCache(1000);
            server.Start(setting);//启动代理


            Console.ReadKey();
        }

        /// <summary>
        /// 初始化配置表
        /// </summary>
        public static void InitConfig()
        {
            //设置配置表的绝对目录
            ConfigManager.Instance.ResPath = @"F:\Game\RPGGameServer\RPGGameServer\ConfigData";
            ConfigManager.Instance.LoadAllCfg();
        }

        public static void TestMySqlAdd()
        {
            ACCOUNT a = new ACCOUNT();
            a.account = "MyName";
            a.password = "123456";
            a.Add();
        }
    }
}
